// pages/index/index.js

Page({
  data:{
    indicatorDots:false,
    autoplay:true,
    interval: 5000,
    duration:500,
    imgUrls: ["../../image/sch1.jpg", "../../image/sch2.jpg"],
    locationIcon:"../../image/location.png"
  

  },
   //分享功能
   onShareAppMessage:function(){
    return {
      title: '油菜花',
      desc: '油菜花',
      path: '/page/common/test'
    }
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    
    //this.setData();
    
  },

  onReady:function(){
    // 页面渲染完成
    //1,加载热门专业数据
    this.loadPopMajorList({pageNum:1,pageSize:10});
    //2.加载热门学校数据
    this.loadPopSchoolList({ pageNum: 1, pageSize: 10 });
   
  },
  
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  openSchoolListWindow:function(){
    wx.navigateTo({
      url: '/page/school/list?categoryId=1'
    })
  },
  openMajarTypeWindow: function () {
    wx.navigateTo({
      url: '/page/majar/majar_type'
    })
  },
  openMajarSchoolListWindow: function (e) {
    
    wx.navigateTo({
      url: '/page/majar/majar_school_list?majorId=' + e.currentTarget.dataset.majorid
    })
  }, 
  openSchoolHomeWindow:function(e){
    wx.navigateTo({
      url: '/page/school/detail?schoolid=' + e.currentTarget.dataset.schoolid
    })
  },
  openSearchWin:function(e){
    wx.navigateTo({
      url: '/page/index/search'
    })
  },
  loadPopMajorList: function (requestObj){
    var self = this;
    wx.request({
      url: getApp().globalData.server + "/major/pop_major_list.do",
      data: requestObj,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        if (res.data.status != 0) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        } else {
          console.log(requestObj);
          console.log(res.data);
          self.setData({
            popMajorList: res.data.data.list
          });
        
        }

      },
      fail: function () {
        wx.showToast({
          title: "获取热门专业失败",
          icon: 'none',
          duration: 1000,
          mask: true
        })
      }
    })
  },
  loadPopSchoolList:function(requestObj){
    var self = this;
    wx.request({
      url: getApp().globalData.server + "/university/pop_university_list.do",
      data: requestObj,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        if (res.data.status != 0) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        } else {
          console.log(requestObj);
          console.log(res.data);
          self.setData({
            popUniversityList: res.data.data.list
          });

        }

      },
      fail: function () {
        wx.showToast({
          title: "获取热门专业失败",
          icon: 'none',
          duration: 1000,
          mask: true
        })
      }
    })
  }
})